#pragma once

#include <windows.h>
#include <d3d11.h>
#include <dxgi1_2.h>
#include <string>

class DXGICapture {
public:
    DXGICapture();
    ~DXGICapture();

    bool Initialize();
    void Cleanup();
    bool CaptureScreen(HBITMAP& hBitmap, int& width, int& height);
    bool IsInitialized() const { return m_initialized; }
    bool IsSupported() const;
    std::string GetLastError() const { return m_lastError; }

private:
    bool InitializeD3D11();
    bool InitializeDXGI();
    HBITMAP ConvertToHBitmap(ID3D11Texture2D* texture);

private:
    bool m_initialized;
    std::string m_lastError;

    ID3D11Device* m_d3d11Device;
    ID3D11DeviceContext* m_d3d11Context;
    IDXGIOutputDuplication* m_dxgiDuplication;
    IDXGIOutput1* m_dxgiOutput;
    IDXGIAdapter1* m_dxgiAdapter;
    IDXGIFactory1* m_dxgiFactory;

    D3D11_TEXTURE2D_DESC m_textureDesc;
};